def left_binary_search(nums, target):
    left, right = 0, len(nums) - 1
    while left <= right:
        mid = (left + right) // 2
        if nums[mid] == target:
            right = mid - 1
        elif nums[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    if nums[left] == target:
        return left
    else:
        return -1


def right_binary_search(nums, target):
    left, right = 0, len(nums) - 1
    while left <= right:
        mid = (left + right) // 2
        if nums[mid] == target:
            left = mid + 1
        elif nums[mid] < target:
            left = mid + 1
        else:
            right = mid - 1

    if nums[right] == target:
        return right
    else:
        return -1


class Solution(object):
    def searchRange(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        if len(nums) == 0 or nums[0] > target or nums[-1] < target:
            return [-1, -1]
        left = left_binary_search(nums, target)
        right = right_binary_search(nums, target)

        return [left, right]


if __name__ == '__main__':
    print(Solution().searchRange([8,8,8,8,8], 8))
